#!/bin/bash

# Gradle startup script for Unix-like systems

# Resolve script directory
DIRNAME=$(dirname "$0")
if [ "$DIRNAME" == "." ]; then
  DIRNAME=$(pwd)
fi
APP_BASE_NAME=$(basename "$0")
APP_HOME="$DIRNAME"

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS="-Xmx64m -Xms64m"

# Find java executable
if [ -z "$JAVA_HOME" ]; then
  JAVA_EXE="java"
else
  JAVA_EXE="$JAVA_HOME/bin/java"
fi

# Check if java executable exists
if ! command -v "$JAVA_EXE" > /dev/null; then
  echo >&2 "ERROR: JAVA_HOME is not set or java command is not found."
  echo >&2 "Please set JAVA_HOME environment variable to your Java installation directory."
  exit 1
fi

# Setup classpath
CLASSPATH="$APP_HOME/gradle/wrapper/gradle-wrapper.jar"

# Execute Gradle
"$JAVA_EXE" $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS -Dorg.gradle.appname="$APP_BASE_NAME" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"

# Check exit status
EXIT_STATUS=$?
if [ $EXIT_STATUS -ne 0 ]; then
  echo >&2 "Gradle execution failed with exit code $EXIT_STATUS"
fi

exit $EXIT_STATUS
